/* Autostop
 *
 * Copyright (c) Maciej Gajewski, Grzegorz Latarowski
 * http://code.google.com/p/autostop-automaty-drogowe
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
 */

#include "serverlistener.h"


// ===========================================================================
//                               ServerListener 
// ===========================================================================


// ------------------- ServerListener::ServerListener() ----------------------
ServerListener::ServerListener( const quint8 serverType )
	: QTcpServer(), _serverType( serverType )
{
	// nope
}
// ---------------------------------------------------------------------------


// ------------------- ServerListener::~ServerListener() ---------------------
ServerListener::~ServerListener()
{
	// nope
}
// ---------------------------------------------------------------------------


// -------------------- ServerListener::listen() -----------------------------
void ServerListener::listen( quint16 port )
{
	QTcpServer::listen( QHostAddress::Any, port );

	while ( waitForNewConnection(-1) )
	{
		// nothing, processing in incomingConnection()
	}
}
// ---------------------------------------------------------------------------


// ----------------- ServerListener::incomingConnection() --------------------
void ServerListener::incomingConnection( int socket )
{
	ServerThread *thread = new ServerThread( _serverType, socket, this );
	connect( thread, SIGNAL( finished() ), thread, SLOT( deleteLater() ) );
	thread->start();
}
// ---------------------------------------------------------------------------




// eof
